package javase.ch02.method;

/**
 * @Desc TODO
 * @Author chenmin
 * @Date 2025/10/30
 */
public class MyThread2 extends Thread{

    private MyThread1 myThread1;

    public MyThread2(String name , MyThread1 myThread1){
        super(name);
        this.myThread1 = myThread1;
    }

    @Override
    public void run() {
        System.out.println("MyThread2 开始执行任务...");
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+" i = "+i);
        }

        //直到MyThread1线程任务执行结束，才会放行，当前线程继续执行任务
        try {
            myThread1.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("MyThread2 结束执行任务...");
    }
}